HOW TO ENABLE WIFI AP AND STA


1. OVERVIEW

sta mode: take wifi as a client to connect AP/router.

ap mode: take wifi as a hotspot for other devices to connect.


2. CODE MODIFICATION AND CONFIGURATION

  1. Config first, then compile.

    1. Enabled wifi by default.

    2. Enable zk_full mode: vim project/release/customer_tailor/nvr_i2m_display_glibc_tailor.mk verify_zk_full:=enable

    3. Delete the last line of code in sdk\verify\application\zk_full\demo.sh to avoid conflicts when the UI calls wifi.

      ........
      
      cd /customer
      
      chmod 777 zkgui
      
      #./zkgui &
      
    4. Compile to update, and then restart.


3. 修改板端行为

  1. Add information of AP

    / # vi appconfigs/wpa_supplicant.conf
    ctrl_interface=/tmp/wifi/run/wpa_supplicant
    update_config=1
    
    network={
        ssid="aryl iPhone"
        psk="123456789a"
    }
    
  2. Initialize wifi

    cd /config/wifi
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/lib:/config/wifi
    ./ssw01bInit.sh
    
  3. Test wifi connection(connect and get the IP, then view it through a router or cell phone)

    ./wpa_supplicant -Dnl80211 -i wlan0 -c /appconfigs/wpa_supplicant.conf -d &
    sleep 2
    udhcpc -q -i wlan0 -s /etc/init.d/udhcpc.script &
    
  4. Scan hotspot

    ./iwlist wlan0 scanning
    
  5. Check the connection status

    ./wpa_cli -i wlan0 -p /tmp/wifi/run/wpa_supplicant status
    
  6. ping

    ping -I wlan0 14.215.177.39
    
  7. DNS mount -o remount,rw / If dns sever is a invalid ip, change it to 8.8.8.

  8. Edit vi /etc/resolv.conf

    export LD_LIBRARY_PATH=$LD_LIBRARY_ifPATH:/customer/libdns
    ping -I wlan0 www.baidu.com
    

    STA mode finished verification when completed the test steps above.

  9. Enable AP mode

    ifconfig p2p0 up
    ifconfig p2p0 192.168.1.100 netmask 255.255.255.0
    ./hostapd -B /config/wifi/hostapd.conf
    ./dnsmasq -i p2p0 --no-daemon -C /config/wifi/dnsmasq.conf &
    

    Check the device information:

    ./hostapd_cli -i p2p0 -p /var/run/hostapd all_sta &
    
  10. Search ssid by PC: ssw101bap; passwd:12345678(ssid and password can be changed in hostapd.conf)

    AP mode finished verification when completed the test steps above.

STA and AP modes finished verification when completed the test steps above.